package com.rongcheng.frc.android_ui_study;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;

import com.rongcheng.frc.android_ui_study.adapter.DividerGridItemDecoration;
import com.rongcheng.frc.android_ui_study.adapter.DividerItemDecoration;
import com.rongcheng.frc.android_ui_study.adapter.FirstRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView myFirstRecyclerView;
    private FirstRecyclerViewAdapter myFirstRecyclerViewAdapter;
    private List<String> items = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initData() {
        for (int i = 'A'; i < 'z'; i++) {
            items.add(""+(char)i);
        }

    }

    private void initView() {
        myFirstRecyclerView = (RecyclerView) findViewById(R.id.first_recycler_view);
        myFirstRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//        myFirstRecyclerView.setLayoutManager(new GridLayoutManager(this,4));
        myFirstRecyclerView.setItemAnimator(new DefaultItemAnimator());
        myFirstRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
//        myFirstRecyclerView.addItemDecoration(new DividerGridItemDecoration(this));
        myFirstRecyclerViewAdapter = new FirstRecyclerViewAdapter(items);
        myFirstRecyclerView.setAdapter(myFirstRecyclerViewAdapter);

        myFirstRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
            @Override
            public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                return false;
            }

            @Override
            public void onTouchEvent(RecyclerView rv, MotionEvent e) {

            }

            @Override
            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

            }
        });


    }

    RecyclerView.ItemDecoration klj = new RecyclerView.ItemDecoration() {
        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
        }

        @Override
        public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDrawOver(c, parent, state);
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
        }
    };
}
